﻿Public Class Juridicas

    Private Sub btnalta_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnalta.Click

        Dim oJuridicasNegocios As New Negocios.Njuridicas
        Dim oJuridicas As New Entidades.Ejuridicas

        If txtdenom.TextLength = 0 Then
            MsgBox("Debe ingresar la denominación", MsgBoxStyle.DefaultButton1, Title:="ERROR")
            txtdenominacion.Focus()
            Exit Sub
        End If
        If IsNumeric(txtdenominacion.Text) Then
            MsgBox("La denominación debe ser solo texto", MsgBoxStyle.DefaultButton1, Title:="ERROR")
            txtdenominacion.Focus()
            txtdenominacion.Text = ""
            Exit Sub
        End If

        If txtcuit.TextLength = 0 Then
            MsgBox("Debe ingresar el número de CUIT", MsgBoxStyle.DefaultButton1, Title:="ERROR")
            txtcuit.Focus()
            Exit Sub
        End If
        If Not IsNumeric(txtcuit.Text) Then
            MsgBox("La número de CUIT debe ser solo numérico", MsgBoxStyle.DefaultButton1, Title:="ERROR")
            txtcuit.Focus()
            txtcuit.Text = ""
            Exit Sub
        End If

        If Not IsNumeric(txttelfijo.Text) Then
            MsgBox("El dato debe ser numerico", MsgBoxStyle.DefaultButton1, Title:="ERROR")
            txttelfijo.Focus()
            txttelfijo.Text = ""
            Exit Sub
        End If

        If Not IsNumeric(txttelmovil.Text) Then
            MsgBox("El dato debe ser numerico", MsgBoxStyle.DefaultButton1, Title:="ERROR")
            txttelmovil.Focus()
            txttelmovil.Text = ""
            Exit Sub
        End If

        If Comboprovincia.Text = "" Then
            MsgBox("Debe seleccionar una provincia", MsgBoxStyle.DefaultButton1, Title:="ERROR")
            Comboprovincia.Focus()
            Exit Sub
        End If
        If Combodepartamento.Text = "" Then
            MsgBox("Debe seleccionar un departamento", MsgBoxStyle.DefaultButton1, Title:="ERROR")
            Combodepartamento.Focus()
            Exit Sub
        End If
        If Combolocalidad.Text = "" Then
            MsgBox("Debe seleccionar una localidad", MsgBoxStyle.DefaultButton1, Title:="ERROR")
            Combolocalidad.Focus()
            Exit Sub
        End If
        If txtcp.TextLength = 0 Then
            MsgBox("Debe ingresar un C.P.", MsgBoxStyle.DefaultButton1, Title:="ERROR")
            txtcp.Focus()
            Exit Sub
        End If
        If Not IsNumeric(txtcp.Text) Then
            MsgBox("El dato debe ser solo numerico", MsgBoxStyle.DefaultButton1, Title:="ERROR")
            txtcp.Focus()
            txtcp.Text = ""
            Exit Sub
        End If


        oJuridicas.fechaalta = UCase(fecha.Text)
        oJuridicas.apenom = UCase(txtdenominacion.Text)
        oJuridicas.numcuit = UCase(txtcuit.Text)
        oJuridicas.telfijo = UCase(txttelfijo.Text)
        oJuridicas.telmovil = UCase(txttelmovil.Text)
        oJuridicas.provin = UCase(Comboprovincia.SelectedValue)
        oJuridicas.dep = UCase(Combodepartamento.SelectedValue)
        oJuridicas.loc = UCase(Combolocalidad.Text)
        oJuridicas.codpostal = UCase(txtcp.Text)
        oJuridicas.domlegal = UCase(txtcalleleg.Text)
        oJuridicas.numlegal = UCase(txtnumleg.Text)
        oJuridicas.pisolegal = UCase(txtpisoleg.Text)
        oJuridicas.dptolegal = UCase(txtdptoleg.Text)
        oJuridicas.domreal = UCase(txtcallere.Text)
        oJuridicas.numreal = UCase(txtnumre.Text)
        oJuridicas.pisoreal = UCase(txtpisore.Text)
        oJuridicas.dptoreal = UCase(txtdptore.Text)

        Try
            If oJuridicasNegocios.guardarjuridicas(oJuridicas) Then
                MsgBox("Está seguro que desea guardar los datos?", MsgBoxStyle.YesNoCancel)

                MsgBox("Los datos se cargaron correctamente", MsgBoxStyle.MsgBoxSetForeground, "Información")
            End If
        Catch ex As Exception
            MsgBox("Carga fallida" + ex.Message, MsgBoxStyle.MsgBoxSetForeground, "Información")
        End Try
        txtdenominacion.Text = ""
        txtcuit.Text = ""
        txttelfijo.Text = ""
        txttelmovil.Text = ""
        txtcp.Text = ""
        txtcalleleg.Text = ""
        txtnumleg.Text = ""
        txtpisoleg.Text = ""
        txtdptoleg.Text = ""
        txtcallere.Text = ""
        txtnumre.Text = ""
        txtpisore.Text = ""
        txtdptore.Text = ""


    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btneliminar.Click
        If (Len(txtcuit.Text) = 0) Then
            MsgBox("El numero de DNI es un  campo obligatorio", MsgBoxStyle.Exclamation)
            txtcuit.Focus()
            Exit Sub
        End If
        Dim oJuridicasNegocios As New Negocios.Njuridicas
        Dim oJuridicas As New Entidades.Ejuridicas
        oJuridicas.numdoc = UCase(txtcuit.Text)
        Try
            If oJuridicasNegocios.eliminarjuridicas(oJuridicas) Then
                MsgBox("La persona juridica se elimino correctamente", MsgBoxStyle.MsgBoxSetForeground, "Información")
            End If
        Catch ex As Exception
            MsgBox("La persona juridicas no se pudo eliminar" + ex.Message, MsgBoxStyle.MsgBoxSetForeground, "Información")
        End Try
        txtdenominacion.Text = ""
        txtcuit.Text = ""
        txttelfijo.Text = ""
        txttelmovil.Text = ""
        txtcp.Text = ""
        txtcalleleg.Text = ""
        txtnumleg.Text = ""
        txtpisoleg.Text = ""
        txtdptoleg.Text = ""
        txtcallere.Text = ""
        txtnumre.Text = ""
        txtpisore.Text = ""
        txtdptore.Text = ""

    End Sub

    Private Sub btnmodificar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnmodificar.Click

        Dim oJuridicasNegocios As New Negocios.Njuridicas
        Dim oJuridicas As New Entidades.Ejuridicas

        oJuridicas.fechaalta = UCase(fechaalta.Text)
        oJuridicas.apenom = UCase(txtdenominacion.Text)
        oJuridicas.numcuit = UCase(txtcuit.Text)
        oJuridicas.telfijo = UCase(txttelfijo.Text)
        oJuridicas.telmovil = UCase(txttelmovil.Text)
        oJuridicas.provin = UCase(Comboprovincia.SelectedValue)
        oJuridicas.dep = UCase(Combodepartamento.SelectedValue)
        oJuridicas.loc = UCase(Combolocalidad.Text)
        oJuridicas.codpostal = UCase(txtcp.Text)
        oJuridicas.domlegal = UCase(txtcalleleg.Text)
        oJuridicas.numlegal = UCase(txtnumleg.Text)
        oJuridicas.pisolegal = UCase(txtpisoleg.Text)
        oJuridicas.dptolegal = UCase(txtdptoleg.Text)
        oJuridicas.domreal = UCase(txtcallere.Text)
        oJuridicas.numreal = UCase(txtnumre.Text)
        oJuridicas.pisoreal = UCase(txtpisore.Text)
        oJuridicas.dptoreal = UCase(txtdptore.Text)
        Try
            If oJuridicasNegocios.modificarjuridicas(oJuridicas) Then
                MsgBox("Está seguro que desea modificar los datos?", MsgBoxStyle.YesNoCancel)

                MsgBox("Los datos se modificaron correctamente", MsgBoxStyle.MsgBoxSetForeground, "Información")
            End If
        Catch ex As Exception
            MsgBox("Modificion fallida" + ex.Message, MsgBoxStyle.MsgBoxSetForeground, "Información")
        End Try

        txtdenominacion.Text = ""
        txtcuit.Text = ""
        txttelfijo.Text = ""
        txttelmovil.Text = ""
        txtcp.Text = ""
        txtcalleleg.Text = ""
        txtnumleg.Text = ""
        txtpisoleg.Text = ""
        txtdptoleg.Text = ""
        txtcallere.Text = ""
        txtnumre.Text = ""
        txtpisore.Text = ""
        txtdptore.Text = ""


    End Sub

    Private Sub Juridicas_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        txtdenom.Focus()
        txtcp.Enabled = False

        Dim ogeneralNegocio As New Negocios.Njuridicas
        Dim ogeneral As New Entidades.Ejuridicas

        DGgeneral.DataSource = ogeneralNegocio.buscargeneral

        Dim oTitularesNegocios As New Negocios.Njuridicas
        Comboprovincia.DataSource = oTitularesNegocios.comboprovin
        Comboprovincia.DisplayMember = " cod_provincia"
        Comboprovincia.ValueMember = "nombre_provincia"

    End Sub

    Private Sub Comboprovincia_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Comboprovincia.KeyPress
        If e.KeyChar = ChrW(Keys.Enter) Then
            Combodepartamento.Focus()
        End If
    End Sub

    Private Sub Comboprovincia_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Comboprovincia.SelectedIndexChanged
        Dim odepartNegocio As New Negocios.Njuridicas
        Dim odepartamento As New Entidades.Ejuridicas

        Combodepartamento.DataSource = odepartNegocio.combodepartamentos(Comboprovincia.Text)
        Combodepartamento.DisplayMember = "cod_departamento"
        Combodepartamento.ValueMember = "nombre_departamento"


    End Sub

    Private Sub Combodepartamento_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Combodepartamento.KeyPress
        If e.KeyChar = ChrW(Keys.Enter) Then
            Combolocalidad.Focus()
        End If
    End Sub

    Private Sub Combodepartamento_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Combodepartamento.SelectedIndexChanged
        Dim olocalidadNegocio As New Negocios.Njuridicas
        Dim olocalidad As New Entidades.Ejuridicas

        Combolocalidad.DataSource = olocalidadNegocio.comboloc(Combodepartamento.Text)
        Combolocalidad.DisplayMember = "cod_localidad"
        Combolocalidad.ValueMember = "nombre_localidad"

    End Sub

    Private Sub Combolocalidad_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Combolocalidad.KeyPress
        If e.KeyChar = ChrW(Keys.Enter) Then
            txtcalleleg.Focus()
        End If
    End Sub

    Private Sub Combolocalidad_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Combolocalidad.SelectedIndexChanged
        txtcp.Text = Combolocalidad.DataSource.rows(Combolocalidad.SelectedIndex)("codigo_postal")
    End Sub

    Private Sub btnbuscar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dgjuridicas.Visible = True

        Dim ojuridicasNegocio As New Negocios.Njuridicas
        Dim ojuridicas As New Entidades.Ejuridicas

        Dgjuridicas.DataSource = ojuridicasNegocio.buscarjuridicas(txtbuscar.Text)

    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        fechaalta.Text = DateTime.Now
    End Sub

    Private Sub Dgjuridicas_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Dgjuridicas.DoubleClick
        Dim i As Integer
        i = Dgjuridicas.CurrentCell.RowIndex

        txtdenom.Text = Dgjuridicas.Rows(i).Cells(0).Value
        txtcuit.Text = Dgjuridicas.Rows(i).Cells(1).Value
        txttelfijo.Text = Dgjuridicas.Rows(i).Cells(2).Value
        txttelmovil.Text = Dgjuridicas.Rows(i).Cells(3).Value
        Comboprovincia.Text = Dgjuridicas.Rows(i).Cells(4).Value
        Combodepartamento.Text = Dgjuridicas.Rows(i).Cells(5).Value
        Combolocalidad.Text = Dgjuridicas.Rows(i).Cells(6).Value
        txtcp.Text = Dgjuridicas.Rows(i).Cells(7).Value
        txtcalleleg.Text = Dgjuridicas.Rows(i).Cells(8).Value
        txtnumleg.Text = Dgjuridicas.Rows(i).Cells(9).Value
        txtpisoleg.Text = Dgjuridicas.Rows(i).Cells(10).Value
        txtdptoleg.Text = Dgjuridicas.Rows(i).Cells(11).Value
        txtcallere.Text = Dgjuridicas.Rows(i).Cells(12).Value
        txtnumre.Text = Dgjuridicas.Rows(i).Cells(13).Value
        txtpisore.Text = Dgjuridicas.Rows(i).Cells(14).Value
        txtdptore.Text = Dgjuridicas.Rows(i).Cells(15).Value

    End Sub

    Private Sub txtcuit_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtcuit.KeyPress

        If e.KeyChar = ChrW(Keys.Enter) Then
            txttelfijo.Focus()
        End If
    End Sub

    Private Sub txttelmovil_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txttelmovil.KeyPress
        If e.KeyChar = ChrW(Keys.Enter) Then
            Comboprovincia.Focus()
        End If
    End Sub

    Private Sub txtcp_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtcp.KeyPress
        If e.KeyChar = ChrW(Keys.Enter) Then
            txtcalleleg.Focus()
        End If
    End Sub

    Private Sub txtcalleleg_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtcalleleg.KeyPress
        If e.KeyChar = ChrW(Keys.Enter) Then
            txtnumleg.Focus()
        End If
    End Sub

    Private Sub txtnumleg_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtnumleg.KeyPress
        If e.KeyChar = ChrW(Keys.Enter) Then
            txtpisoleg.Focus()
        End If
    End Sub

    Private Sub txtpisoleg_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtpisoleg.KeyPress
        If e.KeyChar = ChrW(Keys.Enter) Then
            txtdptoleg.Focus()
        End If
    End Sub

    Private Sub txtdptoleg_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtdptoleg.KeyPress
        If e.KeyChar = ChrW(Keys.Enter) Then
            txtcallere.Focus()
        End If
    End Sub

    Private Sub txtcallere_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtcallere.KeyPress
        If e.KeyChar = ChrW(Keys.Enter) Then
            txtnumre.Focus()
        End If
    End Sub

    Private Sub txtnumre_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtnumre.KeyPress
        If e.KeyChar = ChrW(Keys.Enter) Then
            txtpisore.Focus()
        End If
    End Sub

    Private Sub txtpisore_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtpisore.KeyPress
        If e.KeyChar = ChrW(Keys.Enter) Then
            txtdptore.Focus()
        End If
    End Sub

    Private Sub txtdptore_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtdptore.KeyPress
        If e.KeyChar = ChrW(Keys.Enter) Then
            btnalta.Focus()
        End If
    End Sub

    Private Sub btnalta_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles btnalta.KeyPress
        If e.KeyChar = ChrW(Keys.Enter) Then
            btneliminar.Focus()
        End If
    End Sub

    Private Sub btneliminar_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles btneliminar.KeyPress
        If e.KeyChar = ChrW(Keys.Enter) Then
            btnmodificar.Focus()
        End If
    End Sub

    Private Sub txttelfijo_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txttelfijo.KeyPress
        If e.KeyChar = ChrW(Keys.Enter) Then
            txttelmovil.Focus()
        End If
    End Sub

    Private Sub txtdenom_KeyPress1(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtdenom.KeyPress
        If e.KeyChar = ChrW(Keys.Enter) Then
            txtcuit.Focus()
        End If
    End Sub

    
End Class